#include "mymain.h"

Mymain::Mymain(QWidget *parent):QWidget(parent)
{
    p_login_img=new QLabel;
    p_login_button=new QPushButton(p_login_img);

    p_ip=new QLineEdit(p_login_img);
    p_port=new QLineEdit(p_login_img);

    p_ip->setPlaceholderText("请输入服务器ip");
    p_port->setPlaceholderText("请输入端口");

    QPixmap pix=QPixmap(":/img/jiemian.jpg");
    p_login_img->setPixmap(pix);
    p_login_img->setScaledContents(true);

    QPixmap pixmap(":/img/button.jpg");
    QPixmap fitpixmap = pixmap.scaled(150, 50, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
    p_login_button->setIcon(QIcon(fitpixmap));
    p_login_button->setIconSize(QSize(150, 50));
    p_login_button->setFlat(true);
    p_login_button->setStyleSheet("border: 0px"); //消除边框
    p_login_button->setGeometry(p_login_img->width()*4/6,p_login_img->height()*9.0/10,pixmap.width(),pixmap.height());

    p_ip->setStyleSheet("background-color: rgba(255, 255, 255, 0%); border:0px solid #b9babb;");
    p_port->setStyleSheet("background-color: rgba(255, 255, 255, 0%); border:0px solid #b9babb;");
    p_ip->setGeometry(p_login_img->width()*4/6,p_login_img->height()*7.0/10,pixmap.width(),pixmap.height());
    p_port->setGeometry(p_login_img->width()*4/6,p_login_img->height()*8.0/10,pixmap.width(),pixmap.height());

    QHBoxLayout hboxlayout;
    this->setFixedSize(pix.width(),pix.height());
    hboxlayout.addWidget(p_login_img);
    this->setLayout(&hboxlayout);

    connect(p_login_button,SIGNAL(clicked(bool)),this,SLOT(start_game()));
    connect(p_ip,SIGNAL(textChanged(QString)),this,SLOT(enterip()));
    connect(p_port,SIGNAL(textChanged(QString)),this,SLOT(enterport()));
}


void  Mymain::start_game(){
    if(ready!=0){
        ready=0;
        qDebug()<<"ip and port"<<ip<<port;
        widgetMain=new Widget(ip,port);
        this->hide();
        widgetMain->show();
    }
}


